package Test03;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;

import lesson16.User;

public class LoginClientObject {
	public static void main(String[] args) {
		try {
			//创建Socket对象,第一个参数是服务器IP地址，第二个参数是端口号
			Socket socket = new Socket("localhost", 8800);
			//创建输出流对象
			OutputStream os=socket.getOutputStream();
			ObjectOutputStream oos=new ObjectOutputStream(os);
			//要发送的消息
			User user=new User("Tom","123456");
			//发送消息
			oos.writeObject(user);
			socket.shutdownOutput();
			
			//创建输入流
			InputStream is=socket.getInputStream();
			BufferedReader br=new BufferedReader(new InputStreamReader(is));
			String line=br.readLine();
			while(line!=null) {
				System.out.println(line);
				line=br.readLine();
			}
			
			
			//关闭对象
			is.close();
			oos.close();
			os.close();
			socket.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
